package com.example.handler;

import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;

import java.io.IOException;
import java.io.OutputStream;

public class LoginHandler implements HttpHandler {
    @Override
    public void handle(HttpExchange httpExchange) throws IOException {
        System.out.println("进入LoginHandler");
        String name="hello word";
        Headers requestHeaders = httpExchange.getRequestHeaders();
        for(String key:requestHeaders.keySet()){
            System.out.println("key:"+key+",value:"+requestHeaders.getFirst(key));
        }
        httpExchange.getResponseHeaders().add("content-type","text/html;charset=utf-8");
        httpExchange.sendResponseHeaders(200,name.length());
        OutputStream os = httpExchange.getResponseBody();
        os.write(name.getBytes());
        os.close();
        System.out.println("离开LoginHandler");
    }
}
